package com.example.firstapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {
    public final static String EXTRA_MESSAGE = "com.example.firstapp.MESSAGE";
    // private String str;
    // private final static String text_key = "edittext";
    private EditText textField;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textField = (EditText) findViewById(R.id.edit_message);
        if (savedInstanceState != null) {
            textField.setText((String)savedInstanceState.get(Integer.toString(R.id.edit_message)));
        }
        else {
            textField.setText("Please enter something");
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle savedInstanceState) {
        // savedInstanceState.putString(text_key, textField.getText().toString());

        super.onSaveInstanceState(savedInstanceState); 
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);

        // textField.setText("this is it.");
    }

    @Override
    protected void onStart() {
        super.onStart();
        // str = "Some string";
        // textField.setText(str);
    }

    @Override
    protected void onStop() {
        super.onStop();
        // textField.setText("No here.");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void sendMessage(View view) {
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        String message = textField.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }
    
}
